def is_prime(num):
    if num < 2:
        return False
    for i in range(2, int(num**0.5) + 1):
        if num % i == 0:
            return False
    return True

def get_closest_prime(num):
    if num < 100 or num > 999:
        return "Wrong input"
    
    prime_num = None
    diff = float('inf')
    
    for i in range(num-1, 0, -1):
        if is_prime(i):
            if abs(num - i) < diff:
                prime_num = i
                diff = abs(num - i)
    
    return prime_num

words = input().split()
num_dict = {
    "zero": 0, "one": 1, "two": 2, "three": 3,
    "four": 4, "five": 5, "six": 6,
    "seven": 7, "eight": 8, "nine": 9
}

number = num_dict.get(words[0]) * 100 + num_dict.get(words[1]) * 10 + num_dict.get(words[2])

result = get_closest_prime(number)
print(result)
